package com.Jshop.search.Controller;

import com.Jshop.search.Service.SearchService;
import com.Jshop.search.pojo.SearchRequest;
import com.Jshop.search.pojo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping
public class SearchController {

    @Autowired
    private SearchService searchService;

    //搜索商品
    @PostMapping("page")
    public ResponseEntity<SearchResult> search(
            @RequestBody SearchRequest request
    ){
        SearchResult result = this.searchService.search(request);
        if (result == null){
            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
        }
        return ResponseEntity.ok(result);
    }
}
